import cv2
import filters
from managers import WindowManager, CaptureManager

class Cameo:

    def __init__(self) -> None:
        self._windowManager = WindowManager('Cameo', self.onKeypress)
        self._captureManager = CaptureManager(cv2.VideoCapture(0), 
                                self._windowManager, False)

        self._embossFilter = filters.EmbossFilter()

    def run(self):
        self._windowManager.createWindow()
        while self._windowManager.isWindowCreated:
            self._captureManager.enterFrame()
            frame = self._captureManager.frame
            #filters.strokeEdges(frame, frame)
            self._embossFilter.apply(frame, frame)
            self._captureManager.exitFrame()
            self._windowManager.processEvents()

    def onKeypress(self, keycode):

        if keycode == 32:
            self._captureManager.writeImage('screenshot.png')
        elif keycode == 9: # tab
            if not self._captureManager.isWritingVideo:
                self._captureManager.startWritingVideo("screencast.avi")
            else:
                self._captureManager.stopWritingVideo()
        elif keycode == 27:
            self._windowManager.destroyWindow()

if __name__ == '__main__':
    Cameo().run()
    # http://www.hzcourse.com/oep/resource/access/L29wZW5yZXNvdXJjZXMvdGVhY2hfcmVzb3VyY2UvZmlsZS8yMDIxLzAxL2QyZmM0MWNkNjM5MmQyNTdkMjVhNWM3N2M1YjgzYmExLnppcCQ1Mzk3NS3jgIpPcGVuQ1YgM-iuoeeul-acuuinhuinie-8mlB5dGhvbuivreiogOWunueOsO-8iOWOn-S5puesrDLniYjvvInjgItf5rqQ5Luj56CBLnppcA==